package com.lyc.campuslife.controller;

import com.lyc.campuslife.dto.Result;
import com.lyc.campuslife.dto.UserDTO;
import com.lyc.campuslife.service.IVoucherOrderService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static com.lyc.campuslife.utils.HttpRequestConstants.USER_INFO;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyc
 * @since 2024-05-07
 */
@RestController
@RequestMapping("/voucher-order")
public class VoucherOrderController {
    @Resource
    private IVoucherOrderService voucherOrderService;
    @PostMapping("seckill/{id}")
    public Result seckillVoucher(@PathVariable("id") Long voucherId, HttpServletRequest request){
        UserDTO userDTO = (UserDTO)request.getAttribute(USER_INFO);
        Long userId = userDTO.getId();
        return voucherOrderService.seckillVoucher(voucherId,userId);
    }
}
